package cn.bon.security.filter;

import jakarta.servlet.*;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author: dronff
 * @description:
 * @CreateTime: 2023/12/9 15:29
 **/

@Component
@AllArgsConstructor
//@RequiredArgsConstructor()
@Data
public class HeaderAddFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest httpServletRequest = null;
        HttpServletResponse httpServletResponse = null;
        if (servletRequest instanceof HttpServletRequest ){
            httpServletRequest = (HttpServletRequest) servletRequest;
        }
        if (servletResponse instanceof HttpServletResponse ){
            httpServletResponse = (HttpServletResponse) servletResponse;
        }
        httpServletResponse.addHeader("Access-Control-Expose-Headers","set-tk");
        httpServletResponse.addHeader("Access-Control-Expose-Headers","clear-tk");
        filterChain.doFilter(servletRequest,servletResponse);
    }
}
